<template>
  <div class="app-container">
    <el-row class="filter-container">
      <el-col :span="20">
        <el-input v-model="listQuery.keyword" style="width: 260px;" class="filter-item" prefix-icon="el-icon-search" size="small" placeholder="按手机号/姓名搜索/身份证后6位" clearable />
        <el-select v-model="listQuery.gender" style="width: 80px" class="filter-item" placeholder="性别" size="small" clearable>
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" size="small" @click="handleFilter">
          搜索
        </el-button>
      </el-col>
      <el-col :span="4" class="text-right">
        <el-button v-waves class="filter-item" size="small" icon="el-icon-download" @click="handleDownload">
          导出到 Excel
        </el-button>
      </el-col>
    </el-row>
    <el-tabs v-model="listQuery.status" @tab-click="handleTabs">
      <el-tab-pane label="全部" name="0" />
      <el-tab-pane label="已审核" name="1" />
      <el-tab-pane label="待审核" name="2" />
      <el-tab-pane label="已拒绝" name="3" />
    </el-tabs>
    <el-table ref="dragTable" v-loading="listLoading" :data="list" :height="tableHeight" row-key="id" size="mini" border highlight-current-row style="width: 100%;">
      <el-table-column prop="id" label="ID" align="center" width="80px" />
      <el-table-column prop="title" label="Title" />
      <el-table-column align="center" fixed="right" label="操作" width="100" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" plain size="mini" @click="onPreviewItem(row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="handlePages" />
  </div>
</template>

<script>
import { fetchList } from '@/api/article'
import Pagination from '@/components/Pagination'
import waves from '@/directive/waves'
export default {
  name: 'Table',
  components: { Pagination },
  directives: { waves },
  props: {},
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        limit: 20,
        page: 1,
        gender: '',
        keyword: '',
        status: '0'
      },
      tabIndex: ''
    }
  },
  computed: {
    tableHeight() {
      console.log(this.$store.getters.tableHeight)
      return (this.$store.getters.tableHeight - 92) + 'px'
    }
  },
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    async getList() {
      this.listLoading = true
      const { data } = await fetchList(this.listQuery)
      this.list = data.items
      this.total = data.total
      this.listLoading = false
    },
    handleDownload() {
    },
    handleFilter() {
      this.list = []
      this.listQuery.page = 1
      this.getList()
    },
    handleTabs() {
      this.list = []
      this.listQuery.page = 1
      this.getList()
    },
    handlePages() {
      this.list = []
      this.getList()
    },
    onPreviewItem() {}
  }
}
</script>

<style lang="scss" scoped>
  .pagination-container {
    padding: 32px 16px 0;
  }
</style>
